package cn.zyq.ykb.controller.tk;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.tk.MenuFood;
import cn.zyq.ykb.service.tk.MenuFoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 菜品食材Controller
 *
 * @author SystemAuth
 * @date 2023-10-20
 */

@RestController(value = "MgtMenuFoodController")
@RequestMapping("/api/menuFood")
@Api(tags = "菜品食材接口")
public class MenuFoodController extends BaseController {

    @Autowired
    private MenuFoodService menuFoodService;

    /**
     * 查询菜品食材列表
     */
    @ApiOperation(value = "列表", response = MenuFood.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.menuFoodService.selectMenuFoodList(pageParam);
    }

     /**
      * 导出菜品食材列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "菜品食材" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, @RequestBody PageParam pageParam) {
         List<MenuFood> list = menuFoodService.selectMenuFoodAllList(pageParam);
         ExcelUtil<MenuFood> util = new ExcelUtil<MenuFood>(MenuFood. class);
         util.exportExcel(response, list, "菜品食材数据");
     }

    /**
     * 获取菜品食材详细信息
     */
    @ApiOperation(value = "详情", response = MenuFood.class)
    @GetMapping(value = "/{menuFoodID}")
    public Object getInfo(@PathVariable("menuFoodID") Integer menuFoodID) {
        return this.menuFoodService.selectMenuFoodByMenuFoodID(menuFoodID);
    }
    /**
     * 获取菜品食材详细信息
     */
    @ApiOperation(value = "详情", response = MenuFood.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.menuFoodService.selectMenuFoodByServiceID(serviceID);
    }

    /**
     * 新增菜品食材
     */
    @ApiOperation(value = "新增")
    @Log(title = "菜品食材", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody MenuFood menuFood) {
        return this.menuFoodService.insertMenuFood(menuFood);
    }

    /**
     * 修改菜品食材
     */
    @ApiOperation(value = "编辑")
    @Log(title = "菜品食材", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody MenuFood menuFood) {
        return this.menuFoodService.updateMenuFood(menuFood);
    }

    /**
     * 删除菜品食材
     */
    @ApiOperation(value = "删除")
    @Log(title = "菜品食材", businessType = BusinessType.DELETE)
    @DeleteMapping("/{menuFoodIDs}")
    public Object remove(@PathVariable Integer[] menuFoodIDs) {
        return this.menuFoodService.deleteMenuFoodByMenuFoodIDs(menuFoodIDs);
    }
}
